<template>
  <div>
    <el-card>
      <div slot="header">
        <el-form :inline="true" :model="orderform" size="mini">
          <el-form-item label="订单号">
            <el-input
              v-model="orderform.orderNo"
              placeholder="订单号"
            ></el-input>
          </el-form-item>
          <el-form-item label="收货人">
            <el-input
              v-model="orderform.consignee"
              placeholder="收货人"
            ></el-input>
          </el-form-item>
          <el-form-item label="手机号">
            <el-input v-model="orderform.phone" placeholder="手机号"></el-input>
          </el-form-item>

          <el-form-item label="订单状态">
            <el-select v-model="orderform.orderState" placeholder="订单状态">
              <el-option label="已受理" value="已受理"></el-option>
              <el-option label="派送中" value="派送中"></el-option>
              <el-option label="已完成" value="已完成"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="下单时间">
            <el-date-picker
              v-model="orderform.date"
              type="datetimerange"
              align="right"
              value-format="yyyy-MM-dd HH:mm:ss"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions"
            >
            </el-date-picker>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="onSearch">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="content">
        <el-table :data="tableData" border :style="{ width: w + 'px' }">
          <el-table-column fixed prop="orderNo" label="订单号">
          </el-table-column>

          <el-table-column
            prop="orderTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            label="下单时间"
          >
          </el-table-column>

          <el-table-column prop="phone" label="联系电话"> </el-table-column>

          <el-table-column prop="consignee" label="收货人"> </el-table-column>

          <el-table-column prop="deliverAddress" label="送货地址">
          </el-table-column>

          <el-table-column
            prop="deliveryTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            label="送达时间"
          >
          </el-table-column>

          <el-table-column prop="remarks" label="备注">
          </el-table-column>
          <el-table-column prop="orderAmount" label="订单金额">
          </el-table-column>
          <el-table-column prop="orderState" label="订单状态">
          </el-table-column>

          <el-table-column fixed="right" label="操作">
            <template slot-scope="scope">
              <el-button
                @click="handleClick(scope.row)"
                type="text"
                size="small"
                >查看</el-button
              >
              <el-button type="text" size="small" @click="handleEdit(scope.row)"
                >编辑</el-button>
            </template>
          </el-table-column>
        </el-table>

        <!-- 分页 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>

        <!-- 编辑 -->
        <el-drawer title="修改订单" :visible.sync="drawer">
          <el-form label-width="80px" :model="orderform">
            <el-form-item label="收货人">
              <el-input v-model="orderform.consignee"></el-input>
            </el-form-item>
            <el-form-item label="送货地址">
              <el-input v-model="orderform.deliverAddress"></el-input>
            </el-form-item>
            <el-form-item label="送达时间">
              <el-date-picker
                v-model="orderform.deliveryTime"
                type="datetime"
                placcholder="选择日期时间"
                align="right"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
            <el-button @click="saveEditForm">保存</el-button>
          </el-form>
        </el-drawer>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //快捷键
      editOrderForm: {},
      drawer: false,
      searchData: {}, //搜索参数
      tableData: [], //表格数据
      w: document.body.clientWidth - 300, //表格的宽度
      currentPage: 1,
      pageSize: 8,
      total: 1,
      orderform: {
        orderNo: "",
        consignee: "",
        phone: "",
        orderState: "",
        date: [],
      },
      //快捷键
      pickerOptions: {

      },
    };
  },
  methods: {
    onSearch() {
      this.searchData = { ...this.orderform };
      this.searchData.date = JSON.stringify(this.searchData.date); //chul处理时间
      this.currentPage = 1; //把当前页赋值给第一页
      this.loadData();
    },
    async saveEditForm() {
      //处理下单时间dayjs
      //处理送到时间value- format*="yy-MM-dd HH:mm:ss"
      //时间处理好之后，再发送ajax
    },
    //编辑
    handleEdit(row) {
      this.orderform = { ...row };
      this.drawer = true;
      console.log(row);
    },

    //加载数据
    async loadData() {

    },
    //处理宽度发送改变
    resizeHandle() {
      this.w = document.body.clientWidth - 300;
    },

    //分页
    //每页条数改变触发
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.currentPage = val;
      this.loadData();
    },
    //当前条数改变触发
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.loadData();
    },
    //  saveEditForm()
    handleClick() {
      alert("敬请期待");
    },
  },

  //窗口改变是触发的事件
  created() {
    window.addEventListener("resize", this.resizeHandle);
    this.loadData();
  },
  beforeDestroy() {
    window.addEventListener("resize", this.resizeHandle);
  },
};
</script>

<style lang="less" scoped>
.el-pagination {
  margin: 20px 0;
}
/deep/.el-table__cell{
    text-align: center;
}
</style>
